package com.yangjiangtao.dao;

import com.yangjiangtao.common.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;

@Repository
public class UserDao {
    private JdbcTemplate jdbcTemplate;


    public int getMatchCount(String userName,String password){
        String sqlStr = " select count(*) from test_01.spring_user where user_name = ? and password = ? ";
        return jdbcTemplate.queryForObject(sqlStr,new Object[]{userName,password},Integer.class);
    }

    public User findUserByUserName(String userName){
        String sqlStr = " select user_id from test_01.spring_user where user_name = ? ";
        User user = new User();
        jdbcTemplate.query(sqlStr, new Object[]{userName},
                rs -> {
                    user.setUserId(rs.getInt("user_id"));
                    user.setUserName(userName);
                });
        return user;
    }

}